from json import dumps, load
from os import system, environ


class DoingWithData():
    """ Working with application config. """
    def __init__(self, config: str):
        super(DoingWithData, self).__init__()
        self.config = f'{environ["HOME"]}/.config/anima/{config}.json'

    def get(self) -> dict:
        with open(self.config, 'r') as reads:
            return load(reads)

    def set(self, to_json: dict) -> None:
        if isinstance(to_json, dict):
            with open(self.config, 'w') as json:
                json.write(dumps(to_json, sort_keys=False, indent=4,
                                 ensure_ascii=False, separators=(',', ': ')))
        else:
            system(f'notify-send "Wrong config file type!"')
